<template>
  <view class="toggle-wrapper" @click="toggle">
    <!-- 滑块 -->
    <view class="toggle-slider" :class="{ active: modelValue }">
      <view class="toggle-circle" />
    </view>
    <!-- 左侧文本 -->
    <view class="toggle-text student" :class="{ active: !modelValue }">
      {{ leftText }}
    </view>
    <!-- 右侧文本 -->
    <view class="toggle-text teacher" :class="{ active: modelValue }">
      {{ rightText }}
    </view>
  </view>
</template>

<script lang="ts" setup>
import { defineEmits, defineProps } from 'vue';

// 定义接收的 Props
const props = defineProps({
  modelValue: {
    type: Boolean,
    required: true,
  },
  leftText: {
    type: String,
    default: '新生登录', // 左侧文本默认值
  },
  rightText: {
    type: String,
    default: '教职工登录', // 右侧文本默认值
  },
});

// 定义事件
const emit = defineEmits(['update:modelValue']);

// 切换事件
const toggle = () => {
  console.log('modelValue: ', props.modelValue);
  emit('update:modelValue', !props.modelValue);
};
</script>

<style lang="scss" scoped>
/* 样式与之前一致 */
.toggle-wrapper {
  position: relative;
  width: 100%;
  height: 60px;
  background-color: #e8e8e8;
  border-radius: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
}

.toggle-slider {
  position: absolute;
  width: 50%;
  height: 40px;
  border-radius: 20px;
  transition: all 0.3s ease;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  .toggle-circle{
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    background-color: white;
    width: 90%;
    height: 100%;
    border-radius: 20px;
  }

}

.toggle-slider.active {
  transform: translateX(100%);
}

.toggle-text {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 500;
  color: #a8a8a8;
  transition: color 0.3s ease;
  z-index: 1;
  &.active {
    color: black;
  }
}
</style>
